package com.nhic.blog.repository;

import com.nhic.blog.po.Comment;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment,Long> {

    List<Comment> findByBlogIdAndParentCommentNull(Long blogId, Sort sort);

    @Transactional
    @Modifying
    @Query(value = "delete from Comment c where c.blog.id is null ")
    void deleteComments();
    
    @Transactional
    @Modifying
    @Query(value = "update Comment c set c.blog.id = null where c.blog.id = ?1")
    int updateComments(Long Blogid);
}
